package com.hitrust.gs.action;


/* GSStocksBalanceAction.java
 *
 * Project/Product: JZCG-XMBUS
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2008-8-25	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */
import java.util.ArrayList;
import com.hitrust.gs.bean.GSBalanceParamBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.business.GSManufactureProcessor;
import com.hitrust.gs.business.GSOrganizationProcessor;
import com.hitrust.gs.dao.GSBalanceParamDAO;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.util.date.DateUtil;
public class GSStocksBalanceAction extends GSBaseAction {
    private GSOrganizationProcessor orpro=new GSOrganizationProcessor();
    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
        // TODO Auto-generated method stub
        //取得操作员
        GSOperatorBean oper=(GSOperatorBean) aForm.getSession().getAttribute(GSBaseConstants.LOGIN);
        //取得所有运营公司
        ArrayList ar=orpro.getOrgWarehouse();
        aForm.getRequest().setAttribute("orgware", ar);
        //取得系统设定的结算日期
        GSBalanceParamDAO tBalParmDAO = new GSBalanceParamDAO();
        GSBalanceParamBean tBean = tBalParmDAO.queryBalanceDate();
        String tCurDay = DateUtil.getCurrentDate("yyyyMMdd");
        if(tBean.getGs_balance_date_type().equals(GSBaseConstants.NATURE_BALANCE_DATE)){
            
            int maxday = DateUtil.getMaxMonthDay(tCurDay);
            tBean.setGs_balance_start_date("1");
            tBean.setGs_balance_end_date(String.valueOf(maxday));
            aForm.getRequest().setAttribute("balancestrdate",DateUtil.formateDateTime(DateUtil.getSpecDay(1)));
            aForm.getRequest().setAttribute("balanceenddate",DateUtil.formateDateTime(DateUtil.getSpecDay(maxday)));
        }else{//手动设定参数类型
            int tStrDay = Integer.parseInt(tBean.getGs_balance_start_date());
            int tEndDay = Integer.parseInt(tBean.getGs_balance_end_date());
            int curYear = Integer.parseInt(tCurDay.substring(0,4));
            int curMonth = Integer.parseInt(tCurDay.substring(4,6));
            if(tStrDay > tEndDay || tStrDay == tEndDay){    //开始日期大于等于结束日期
                if(tCurDay.substring(4,6).equals("01")){    //如果当前月份为1月,则开始区间的年为上一年份
                    aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear-1,12,tStrDay,"yyyy-MM-dd"));    
                    aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,1,tEndDay,"yyyy-MM-dd"));
                }else {
                    aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear,curMonth - 1,tStrDay,"yyyy-MM-dd"));    
                    aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,curMonth,tEndDay,"yyyy-MM-dd"));
                }  
            }else if(tStrDay < tEndDay){        //开始日期小于结束日期
                aForm.getRequest().setAttribute("balancestrdate",DateUtil.getSpecDate(curYear,curMonth,tStrDay,"yyyy-MM-dd"));    
                aForm.getRequest().setAttribute("balanceenddate",DateUtil.getSpecDate(curYear,curMonth,tEndDay,"yyyy-MM-dd"));
            }
        }
      //种类等级
        GSManufactureProcessor tGSManufProcessor = new GSManufactureProcessor();
        tGSManufProcessor.getManufactureOfLevel(aForm);
        //出货单位
        ArrayList array=orpro.getOrgSub(oper.getGs_oper_org_id());
        aForm.getRequest().setAttribute("orgship", array);
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
